package org.jing.ext.socket;

import org.jing.core.lang.data.BaseSerializableDto;
import org.jing.core.lang.JingException;
import org.jing.core.util.StringUtil;

/**
 * Description: 监听服务配置基类 <br>
 *
 * @author bks <br>
 * @since 2024-07-08 <br>
 */
public abstract class BaseSocketServerConfig extends BaseSerializableDto {

    public abstract void setCode(String code);

    public abstract String getCode();

    public abstract void setName(String name);

    public abstract String getName();

    public abstract void setPort(int port);

    public abstract int getPort();

    public abstract void setEncoding(String encoding);

    public abstract String getEncoding();

    public abstract void setTimeout(long timeout);

    public abstract long getTimeout();

    public abstract void setLimit(int limit);

    public abstract int getLimit();

    @Override public void after() {
        // 必填校验
        if (StringUtil.isEmpty(getCode())) {
            throw new JingException("[{}] required", Const.KEY_CODE);
        }
        setName(StringUtil.ifEmpty(getName(), getCode()));
        // 端口校验
        if (0 >= getPort()) {
            throw new JingException("invalid [{}]: {}", Const.KEY_PORT, getPort());
        }
    }
}
